package fr.umlv.m2.uwp2011.persistence.matiere;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CollectionOfElements;

@SuppressWarnings("serial")
@Entity
@Table(name ="MATIERE")
public class Matiere implements Serializable {
	
	@Id
	@GeneratedValue
	@Column(name="MATIERE_ID")
	private Long id;
	
	@Column(name="MATIERE_LIBELLE")
	private String libelle;
	
	@CollectionOfElements //à faire
	@Cascade(org.hibernate.annotations.CascadeType.MERGE)
	@JoinTable(
    name = "Keywords", 
    joinColumns = @JoinColumn(name = "MATIERE_ID", columnDefinition ="INTEGER UNSIGNED"))
	@Column(
	   name = "KEYWORD_TEXT",
	   columnDefinition="VARCHAR(60)"
	)
	List<String> keywords;
	
	@ManyToMany(mappedBy="listMatiere")
	List<TroncCommun> listTroncCommun;
		
	
	@Column(name="matiere_descriptif")
	private String descriptif;
	
	
	public String getLibelle() {
		return libelle;
	}
	public void setLibelle(String libelle) {
		this.libelle = libelle;
	}
	public Iterator<String> iteraotorKeywords() {
		return keywords.iterator();
	}
	public void setKeywords(List<String> keywords) {
		this.keywords = keywords;
	}
	public String getDescriptif() {
		return descriptif;
	}
	public void setDescriptif(String descriptif) {
		this.descriptif = descriptif;
	}
	
	public Iterator<TroncCommun> iteratorTroncCommun() {
		return listTroncCommun.iterator();
	}
	
	public void setListTroncCommun(List<TroncCommun> listTroncCommun) {
		this.listTroncCommun = listTroncCommun;
	}
	
	public Long getId() {
		return id;
	}

}
